package seqlist.oj;

/**
 * @Author: yuisama
 * @Date: 2019/12/6 17:14
 * @Description:链表的中间节点-快慢指针法(一次遍历取得结果)
 * https://leetcode-cn.com/problems/middle-of-the-linked-list/description
 */
public class Solution876_1 {
    public ListNode middleNode(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode low = head;
        ListNode fast = head.next;
        while (fast != null && fast.next != null) {
            low = low.next;
            fast = fast.next.next;
        }
        if (fast == null) {
            return low;
        }else {
            return low.next;
        }
    }
}
